import { WeaTable, WeaLocaleProvider } from 'ecCom';
const getLabel = WeaLocaleProvider.getLabel;

export default class LogItem extends React.Component {
    constructor(props){
        super(props);
    }
    getOperatorDom(id, name, depid, depname, isagent){
        if(!isagent && parseInt(id)<0)
            return <span style={{fontSize:"14px"}}>{name}</span>;
        else
            return (
                <span style={{fontSize:"14px"}}>
                    <a href={`/hrm/company/HrmDepartmentDsp.jsp?id=${depid}`} target="_blank">{depname}</a>
                    {
                        depname !== "" && <span style={{padding:"0px 2px"}}>/</span>
                    }
                    <a href={`javaScript:openhrm(${id})`} onClick={event=>window.pointerXY(event)}>{name}</a>
                    {
                        isagent && <span style={{padding:"0px 2px"}}>-></span>
                    }
                </span>
            );
    }
    render() {
        const { data,index } = this.props;
        return (
            <div className="wf-log-item" style={{paddingTop:`${index==0 ? 0 : 24}px`}}>
                <div className="wf-log-describe">
                    {
                        data.agentid>0 && this.getOperatorDom(data.agentid, data.agentid_name, data.agentid_depid, data.agentid_depname, true)
                    }
                    {this.getOperatorDom(data.modifierid, data.modifierid_name, data.modifierid_depid, data.modifierid_depname, false)}
                    <span style={{paddingLeft:"20px"}}>{data.modifytime}</span>
                    {
                        parseInt(data.modifierid)>0 && <span style={{paddingLeft:"20px"}}>{`IP:${data.modifierip}`}</span>
                    }
                </div>
                {
                    data.mainLog && data.mainLog.length>0 &&
                    <div className="wf-log-main">
                        {
                            data.mainLog.map((item,index) =>{
                                return <div className="wf-log-mainitem">
                                    <span>{index+1}.</span>
                                    <span style={{fontWeight:"bold", paddingLeft:"4px"}}>[</span>
                                    <span>{item.fieldlabel}</span>
                                    <span style={{fontWeight:"bold"}}>]</span>
                                    <span style={{padding:"0px 4px"}}>{getLabel('623',"由")}</span>
                                    <span>"</span>
                                    <span style={{color:"red"}} dangerouslySetInnerHTML={{__html:item.show1}}></span>
                                    <span>"</span>
                                    <span style={{padding:"0px 4px"}}>{getLabel('21623',"改为")}</span>
                                    <span>"</span>
                                    <span style={{color:"red"}} dangerouslySetInnerHTML={{__html:item.show2}}></span>
                                    <span>"</span>
                                </div>
                            })
                        }
                    </div>
                }
                {
                    data.detailLog && data.detailLog.length>0 && data.detailLog.map((group,gindex) =>{
                        return  <div className="wf-log-detail" style={{paddingTop:`${gindex==0 ? 14 : 24}px`}}>
                            <WeaTable ecId={`${this && this.props && this.props.ecId || ''}_WeaTable@ephati@${gindex}`} 
                                scroll={{x: true}}
                                columns={group.columns}
                                dataSource={group.dataSource}
                                draggable={false}
                                pagination={false}
                            />
                        </div>
                    })
                }
            </div>
        )
    }
}